<template>
  <div class="web-container info">
    <div class="nav">
      <span class="router-title">当前位置：<router-link to="/">首页</router-link> > <router-link to="/newspaper">报纸</router-link> > <span class="title">{{this.$route.query.value}}</span></span>
    </div>
    <div class="content">
      <div class="content-left">
        <div class="content-top">
          <div class="content-top-left">
            <img class="content-cover" :src="'http://c61.cnki.net/ccnd/'+cover+'.jpg'" alt="">
            <span class="content-read">124567人在读</span>
            <span class="content-year">出版年:2018年8月</span>
            <div class="content-btn">
              <el-button type="primary" round @click="goToContent">阅&nbsp;读</el-button>
              <ul>
                <li @click="toggleCollec(collect.whetherCollection)" :class="collect.whetherCollection==1 ? 'active':''"><i class="iconfont icon-shoucang"></i>收藏</li>
                <!-- <li><i class="iconfont icon-fenxiang"></i>分享</li> -->
              </ul>
            </div>
          </div>
          <div class="content-top-right">
            <span class="content-title" v-html="bookName">
              生而不凡
            </span>
            <span class="content-author" v-html="'第'+FromatPushTime(new Date(Number(newNews.date)))+'期'"></span>
          </div>
        </div>
        <div class="content-bottom">
          <span class="title">往期</span>
          <div class="desc">
            <span v-for="(item,index) in classList" :key="index" class="item" @click="setnewNews(item)" :class="item.date===newNews.date?'border-green':''">第{{FromatPushTime(new Date(Number(item.date)))}}期</span>
          </div>
        </div>
      </div>
      <div class="content-right">
        <div class="read-box">
          <el-tabs v-model="activeName2" type="card">
            <!-- <el-tab-pane label="移动端阅读" name="first">
              <span class="scan">
               <img  src="/static/images/base/code.jpg" style="width: 135px;" alt="">
              </span>
              <span class="scan">扫描二维码</span>
            </el-tab-pane> -->
            <el-tab-pane label="关注公众号" name="second">
              <span class="scan">
               <img  src="/static/images/base/code.jpg" style="width: 135px;" alt="">
              </span>
              <span class="scan">扫描关注公众号</span>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { GetNewInfoList,GetBookCode } from "@/api/Api";
import { isCollect, addCollect, delCollect } from "@/api/index";
export default {
  data() {
    return {
      classList: [{ data: null }],
      cover: null,
      bookName: null,
      pageSize: 6,
      currentPage: Number(this.$route.query.currentPage) || 1,
      total: 0,
      newNews: {},
      loading: true,
      collect: {},
      activeName2: "second"
    };
  },
  created() {
    this.currentPage = Number(this.$route.query.currentPage) || 1;
    GetNewInfoList(
      this.$route.query.resourceType,
      this.$route.query.value,
      this.currentPage,
      this.pageSize
    ).then(result => {
      this.loading = false;
      this.classList = result.data;
      this.newNews = result.data[0];
      this.cover = this.$route.query.max_file_name;
      this.bookName = this.$route.query.value;
      this.total = result.total;
      this.currentPage = Number(this.$route.query.currentPage) || 1;
      this.isCollect();
    });
  },
  components: {},
  methods: {
    replaceName(n){
        n.replaceAll(/http://c61.cnki.net/ccnd/g,'')
    },
    //是否收藏 添加 阅读数
    isCollect() {
      if(this.$store.state.isLogin == 0){
         this.$store.commit("SET_LOGINSHOW", true);
         return;
      }
      isCollect(this.bookName, 4).then(res => {
        console.log(res.data.date);
        this.collect = res.data.date;
      });
    },
    //查询是否收藏
    toggleCollec(is) {
      if (is == 0) {
        const cover = 'http://c61.cnki.net/ccnd/'+this.cover+'.jpg'
        addCollect(4, cover, this.bookName, "", this.bookName).then(
          res => {
            console.log(res.data);
            this.$message({
              message: '收藏成功',
              type: 'success',
              center: true
            });
          }
        );
      } else {
        delCollect(this.collect.collectionId).then(res => {
          console.log(res.data);
          this.$message({
              message: '移除收藏',
              type: 'success',
              center: true
            });
        });
      }
      this.isCollect();
    },
    goToContent() {
      if(this.$store.state.isLogin == 0){
         this.$store.commit("SET_LOGINSHOW", true);
         return;
      }
      this.$router.push(
        "/newspaper/list?resourceType=" +this.$route.query.resourceType +"&value=" +this.newNews.date +"&name=" +this.$route.query.value +"&max_file_name=" +this.$route.query.max_file_name
      );
    },
    setnewNews(item) {
      this.newNews = item;
    }
  }
};
</script>
<style lang="less" scoped>
.custom-dz{
  .info .content .content-left .content-bottom .title{
    color: #e93926;
  }
}
.info {
  .border-green {
    border: 1px solid green !important;
    box-shadow: 0 0 3px 3px #409eff;
  }
  .nav {
    overflow: hidden;
    padding: 30px 0;
    .router-title{
    font-size: 15px;
  }
  }
  .content {
    min-height: 400px;
    background: #fff;
    border-radius: 10px;
    padding: 30px 128px;
    display: flex;
    .content-left {
      flex: 1;
      .content-top {
        display: flex;

        .content-top-left {
          display: flex;
          flex-direction: column;
          .content-cover {
            margin-bottom: 34px;
            width: 326px;
            height: 116px;
            border-radius: 10px;
          }
          .content-press,
          .content-year,
          .content-read {
            font-size: 16px;
            color: #808080;
            margin-top: 16px;
          }
          .content-btn {
            margin-top: 45px;
            display: flex;
            li.active{
              color:red;
              .icon-shoucang{
                color: red;
              }
            }
            .el-button {
              // background-color: #15c798;
              line-height: 32px;
              width: 110px;
              font-size: 16px;
              padding: 0px 20px;
              border: 2px solid transparent;
              .el-button--primary:focus,
              .el-button--primary:hover {
                // background-color: #15c798;
              }
            }
            ul {
              padding-left: 0px;
              width: 100%;
              text-align: right;
              display: flex;
              justify-content: flex-end;
              li {
                // float: left;
                cursor: pointer;
                line-height: 42px;
                font-size: 16px;
                color: #808080;
                display: flex;
                align-items: center;
                padding: 0 15px;
                i {
                  font-size: 30px;
                  margin-right: 5px;
                }
              }
            }
          }
        }
        .content-top-right {
          margin-left: 30px;
          height: 264px;
          display: flex;
          flex: 1;
          width: 100%;
          flex-direction: column;

          .content-title {
            font-size: 24px;
            font-weight: bold;
          }
          .content-author,
          .content-press,
          .content-year,
          .content-read {
            font-size: 16px;
            color: #808080;
            margin-top: 16px;
          }
        }
      }
      .content-bottom {
        .title {
          display: block;
          padding: 15px 25px;
          font-size: 16px;
          color: #15c798;
          font-weight: bold;
          border-bottom: 1px solid #c1c1c1;
          position: relative;
        }
        .title::after {
          content: "";
          display: inline-block;
          width: 8px;
          height: 8px;
          background: #fff;
          border-top: 1px solid #c1c1c1;
          border-right: 1px solid #c1c1c1;
          transform: rotate(-45deg);
          position: absolute;
          bottom: -5px;
          left: 35px;
        }
        .desc {
          padding: 0px 0px 150px 0px;
          font-size: 16px;
          line-height: 30px;
          display: flex;
          flex-wrap: wrap;
          color: #a1a1a1;
          .item {
            width: 130px;
            margin-left: 46px;
            border-radius: 18px;
            height: 36px;
            line-height: 36px;
            border: 1px solid #a1a1a1;
            text-align: center;
            margin-top: 30px;
            user-select: none;
            cursor: pointer;
          }
          .item:nth-child(4n + 1) {
            margin-left: 0px;
          }
        }
      }
    }
    .content-right {
      width: 223px;
      margin-left: 30px;
      user-select: none;
      .read-box {
        width: 100%;
        border-radius: 10px;
        background: #ecfcf8;
        box-shadow: #e6e6e6 2px 2px 10px;
        .scan {
          display: block;
          text-align: center;
          font-size: 14px;
          padding: 6px 0;
          color: #808080;
        }
        .title {
          display: block;
          padding: 20px 0px 14px 20px;
          font-size: 18px;
          font-weight: bold;
          border-bottom: 1px solid #c8e2dc;
        }
        .code {
          margin-left: 52px;
        }
        .system {
          display: flex;
          justify-content: space-between;
          padding: 20px 45px;
          cursor: pointer;
          span {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: #15c798;
            img {
              margin-bottom: 10px;
            }
          }
        }
      }
    }
  }
}
</style>


